{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>你好\n",
      "服务端 ：[2019-08-08 15:43:10]:你好\n",
      ">>hello world\n",
      "服务端 ：[2019-08-08 15:43:16]:hello world\n",
      ">>quit\n",
      "服务端 ：[2019-08-08 15:43:27]:quit\n",
      ">>exit\n",
      "服务端 ：[2019-08-08 15:43:31]:exit\n"
     ]
    }
   ],
   "source": [
    "from socket import *\n",
    "from time import ctime\n",
    "\n",
    "COD = 'utf-8'\n",
    "HOST = '10.32.3.200'\n",
    "PORT = 9013\n",
    "BUFSIZE = 1024\n",
    "ADDR = (HOST,PORT)\n",
    "tcpCliSock = socket(AF_INET, SOCK_STREAM) #创建socket对象\n",
    "tcpCliSock.connect(ADDR) #连接服务器\n",
    "while True:\n",
    "    data = input('>>').strip()\n",
    "    if not data:\n",
    "        break\n",
    "    tcpCliSock.send(data.encode('utf-8')) #发送消息\n",
    "    data = tcpCliSock.recv(BUFSIZE) #读取消息\n",
    "    if not data:\n",
    "        break\n",
    "    print(data.decode('utf-8'))\n",
    "tcpCliSock.close() #关闭客户端"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
